package com.wz.demo.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.wz.demo.entity.SysUser;
import com.wz.demo.mapper.SysUserMapper;
import com.wz.demo.service.SysUserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 用户 服务实现类
 * </p>
 *
 * @author wangze123
 * @since 2018-03-02
 */
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Override
    public SysUser findByUserName(String userName) {
        return this.selectOne(new EntityWrapper<SysUser>().eq("login_name", userName));
    }


    @Transactional
    public boolean addTestUser(int id, String salt, String password) {
        SysUser user = this.selectById(id);
        if (user == null) {
            throw new RuntimeException("当前用户不存在");
        }
        user.setSalt(salt);
        user.setPassword(password);
        return this.updateById(user);
    }
}
